<script type="text/javascript"><!--//--><![CDATA[//><!--

	var grid_reload = function(){
		$('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
	};

	$(document).ready(function() {



		// Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			columns:[[ //edit nanti
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },				
				{ field : 'kode_mitra', title : 'Kode Mitra', width:200, sortable:true },	
				{ field : 'nama_mitra', title : 'Nama Mitra', width:200, sortable:true },	
				{ field : 'nama_pemilik', title : 'Nama Pemilik', width:200, sortable:true },	
				{ field : 'no_kontrak', title : 'Nomor Kontrak', width:200, sortable:true },				
				//{ field : 'tanggal_kontrak', title : 'Tanggal Kontrak', width:170, sortable:true }			
			]]
		});
		
		$('#filter_app_id').setCombo({ data: <?php echo json_encode($arr_application); ?> });
		
		// Setup Form
		$('#form_master').setupForm([
			{ name: 'kode_mitra', type:'text', size: 'medium', noempty:true },
			{ name: 'nama_mitra', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'alamat_lengkap', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_telp', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_fax', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'jenis_usaha', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'jenis_produk', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'npwp', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'website', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'email', type: 'text', size: 'medium', maxlength: 100, noempty:true },

			{ name: 'kode_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'nama_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'alamat_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_telp_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_hand_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_fax_pemilik', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'website_pemilik', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'email_pemilik', type: 'text', size: 'medium', maxlength: 100, noempty:true },

			{ name: 'no_kontrak', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			//{ name: 'tanggal_kontrak', type: 'date', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'awal_kerja', type: 'date', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'akhir_kerja', type: 'date', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'fee_mitra', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'biaya_katalog', type: 'text', size: 'medium', maxlength: 100, noempty:true },

			{ name: 'no_rekening', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'nama_bank', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'atas_nama', type: 'text', size: 'medium', maxlength: 100, noempty:true }
		]);
		
		$('#dialog_container').tabs({  
			border:false,
			onSelect:function(title){  
					return false;
			}  
		}); 
		
		// Create Dialog
		$('#dialog_container').dialog({
			closed:true,
			modal:true,
			title: 'Add Mitra',
			width:750,
			height:550,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					$('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#dialog_container').dialog('close');
				}
			}]
		});
		
		
		// Set Action Button
		var buttons = [ { label: 'Add', icon: 'add', onclick: function() {
							resetError();
							$('#dialog_container').dialog('open');
							$('#form_master').data('mode', 'create');
							$('#form_master').parent().parent().parent().prev().find('.panel-title').html('New Mitra');
							$('#kode_mitra').readonly(false);
							$('#kode_mitra, #nama_mitra, #alamat_lengkap, #no_telp, #no_fax, #jenis_usaha, #jenis_produk, #npwp, #website, #email, #kode_pemilik, #nama_pemilik, #alamat_pemilik, #no_telp_pemilik, #no_hand_pemilik, #no_fax_pemilik, #website_pemilik, #email_pemilik, #no_kontrak, #awal_kerja, #akhir_kerja, #fee_mitra, #no_rekening, #nama_bank, #atas_nama').val('');
							$('#kode_mitra').focus();
						} },
						{ label: 'Edit', icon: 'edit', onclick: function() {
							var oSel=$('#datagrid').datagrid('getSelected'); 
							if(oSel==null){ alert('Please select row!'); }
							else{ 
								resetError();
								$('#dialog_container').dialog('open'); 
								$('#form_master').data('mode', 'edit');
								$('#form_master').parent().parent().parent().prev().find('.panel-title').html('Edit Mitra');
								$('#kode_mitra').readonly();
								jsonToForm(oSel); $('#nama_mitra').focus();
							} 
						} },
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['kode_mitra']);
							} 
						}},

						{ label: 'Show', icon: 'Show', onclick: function() {
							var oSel=$('#datagrid').datagrid('getSelected'); 
							if(oSel==null){ alert('Please select row!'); }
							else{ 
								resetError();
								$('#dialog_container').dialog('open'); 
								$('#form_master').data('mode', 'edit');
								$('#form_master').parent().parent().parent().prev().find('.panel-title').html('Show Mitra');
								$('#kode_mitra').readonly();
								jsonToForm(oSel); $('#nama_mitra').focus();
							} 
						} },];
		setAction(buttons);
		
		
		$('#fm_search').focusFirst();

		 

	});
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>


<div id="dialog_container" class="easyui-tabs">
		<div title="Data Mitra" style="padding:20px;">
			<form id="form_master">
			<table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
		        <tr>
		    		<td><font size ='3px'><strong><u>Data Mitra</u></strong></td>
		    		<td></td>
				</tr>
				<tr>
		        	<td class="label">Kode Mitra</td>
		        	<td><input id="kode_mitra" /></td>
		 		</tr>
		 		<tr>
		 			<td class="label">Nama Mitra</td>
		        	<td><input id="nama_mitra" /></td>
		    	</tr>
		    	<tr>
		       		<td class="label">Alamat Toko</td>
		       		<td><input id="alamat_lengkap" /></td>
				</tr>
				<tr>
		        	<td class="label">Nomor Telepon</td>
					<td><input id="no_telp" /></td>
		  		</tr>
		  		<tr>
		        	<td class="label">Nomor Fax</td>
		        	<td><input id="no_fax" /></td>
		 		</tr>
		 		<tr>
		        	<td class="label">Jenis Usaha</td>
		        	<td><input id="jenis_usaha" /></td>
				</tr>
				<tr>
		        	<td class="label">Jenis Produk</td>
		        	<td><input id="jenis_produk" /></td>
				</tr>
				<tr>
		        	<td class="label">NPWP</td>
		        	<td><input id="npwp" /></td>
				</tr>
				<tr>
		        	<td class="label">Website</td>
		        	<td><input id="website" /></td>
				</tr>
				<tr>
		        	<td class="label">Email</td>
		        	<td><input id="email" /></td>
				</tr>
			</table>
			</form>
	    </div>

	    <div title="Pemilik Mitra" data-options="closable:true" style="overflow:auto;padding:20px;">
	    	<form id="form_master">
	    	<table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
			    <tr>
			       	<td><font size ='3px'><strong><u>Pemilik Mitra</u></strong></td>
			    	<td></td>
			    </tr>
			    <tr>
			        <td class="label">Kode Pemilik</td>
			        <td><input id="kode_pemilik" /></td>
			    </tr>
			    <tr>
			        <td class="label">Nama Pemilik</td>
			        <td><input id="nama_pemilik" /></td>
			    </tr>
			    <tr>
			        <td class="label">Alamat Pemilik</td>
			        <td><input id="alamat_pemilik" /></td>
			    </tr>
			    <tr>
			        <td class="label">Nomor Telepon</td>
			        <td><input id="no_telp_pemilik" /></td>
			    </tr>
			    <tr>
			        <td class="label">Nomor Handphone</td>
			        <td><input id="no_hand_pemilik" /></td>
			    </tr>
			    <tr>
			        <td class="label">Nomor Fax</td>
			        <td><input id="no_fax_pemilik" /></td>
			    </tr>
			    <tr>
			        <td class="label">Website</td>
			        <td><input id="website_pemilik" /></td>
			    </tr>
			    <tr>
			        <td class="label">Email</td>
			        <td><input id="email_pemilik" /></td>
			    </tr>
	    	</table>
	   		</form>
	    </div>
	    <div title="Kontrak Kerjasama" data-options="iconCls:'icon-reload',closable:true" style="padding:20px;">
	    	<form id="form_master">
	    	<table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
			    <tr>
			    	<td><font size ='3px'><strong><u>Kontrak Kerjasama</u></strong></td>
			    	<td></td>
				</tr>
				<tr>
			        <td class="label">Nomor Kontrak</td>
			        <td><input id="no_kontrak" /></td>
			    </tr>
			    <tr>
			    <td class="label">Awal Kerjasama</td>
			        <td><input id="awal_kerja" /></td>
			    </tr>
			    <tr>
			        <td class="label">Akhir Kerjasama</td>
			        <td><input id="akhir_kerja" /></td>
			 	</tr>
			    <tr>
			        <td class="label">FEE Mitra</td>
			        <td><input id="fee_mitra" /></td>
				</tr>
			</table>
			</form>
	    </div>
	    <div title="Bank" data-options="iconCls:'icon-reload',closable:true" style="padding:20px;">
	   		<form id="form_master">
	   		<table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
			    <tr>
			    	<td><font size ='3px'><strong><u>Bank</u></strong></td>
			    	<td></td>
			    </tr>
			    <tr>
			 		<td class="label">Nomor Rekening</td>
			        <td><input id="no_rekening" /></td>
			    </tr>
			    <tr>
					<td class="label">Nama Bank</td>
			        <td><input id="nama_bank" /></td>
				</tr>
				<tr>
					<td class="label">Atas Nama</td>
			        <td><input id="atas_nama" /></td>
			    </tr>
			</table>
			</form>
	    </div>
	
</div>